package com.prpat;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

public class PassToNext implements Runnable
{
	private Message message;
	private Socket incoming;

	/**
	 * {@link ObjectInputStream} to read {@link Message messages} from.
	 */
	private ObjectInputStream in;

	PassToNext(Socket clientSocket)
	{
		incoming = clientSocket;
	}

	public void run() 
	{
		try 
		{
			in = new ObjectInputStream(incoming.getInputStream());
			message = (Message) in.readObject();
			in.close();
			Sender.sendMessage(message);
		} 
		catch (IOException ioe) {
			System.err.println(ioe.getMessage());
		} 
		catch (ClassNotFoundException cnfe) {
			System.err.println(cnfe.getMessage());
		}
	}

}
